﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ImageListDemo
{
    public partial class Form1 : Form
    {

        private string _path;

        private List<string> imgLIST = new List<string>();
        public Form1()
        {
            InitializeComponent();
        }

        //打开文件夹
        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderBrowerDialog = new FolderBrowserDialog();
            if(folderBrowerDialog.ShowDialog() == DialogResult.OK)
            {
                if(folderBrowerDialog.SelectedPath.Trim() != string.Empty)
                {
                    _path = this.textBox1.Text = folderBrowerDialog.SelectedPath;
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            _path = textBox1.Text;
            if (string.IsNullOrEmpty(_path)) return;

            imgLIST.Clear();
            imageList1.Images.Clear();
            listView1.Items.Clear();

            DirectoryInfo dirInfo = new DirectoryInfo(_path);
            FileInfo[] files = dirInfo.GetFiles();

            foreach(var item in files)
            {
                imgLIST.Add(_path + "\\" + item.Name);
            }

            for(int index = 0; index < imgLIST.Count; index++)
            {
                Bitmap bitMap = new Bitmap(Image.FromFile(imgLIST[index]), 200, 150);
                //Bitmap bitMap = new Bitmap(Image.FromFile(imgLIST[index]));
                imageList1.Images.Add(bitMap);
                listView1.Items.Add(Path.GetFileName(imgLIST[index]),index);
                listView1.Items[index].ImageIndex = index;
                listView1.Items[index].Name = imgLIST[index];
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            List<string> checkList = new List<string>();
            foreach(ListViewItem item in listView1.Items)
            {
                if(item.Checked)
                {
                    checkList.Add(item.Name);
                }
            }
        }
    }
}
